2 Problem: 610 - Street directions (UVa online judge)
4 Author: Andrés Mejía-Posada (http://github.com/andmej/acm)
5 Algorithm: Depth-first search
11 const int MAXN
= 1000;
13 bool g
[MAXN
][MAXN
], visited
[MAXN
];
14 int n
, p
[MAXN
]; //p[i] = nodo predecesor que me llevó al nodo i.
18 for (int v
=0; v
<n
; ++v
){
19 if (g
[u
][v
]){ //hay arista
20 if (visited
[v
] && v
!= p
[u
]){ //encontre un ciclo
23 while(previous
!= v
){ //Volver de una sola vía todas las aristas del ciclo
24 g
[previous
][p
[previous
]] = false;
25 previous
= p
[previous
];
27 }else if (!visited
[v
]){
37 while (scanf("%d %d", &n
, &m
) == 2 && (n
+m
)){
38 for (int i
=0; i
<n
; ++i
){
39 for (int j
=0; j
<n
; ++j
){
48 scanf("%d %d", &u
, &v
);
50 g
[u
][v
] = g
[v
][u
] = true;
54 printf("%d\n\n", C
++);
55 for(int i
=0; i
<n
; ++i
){
56 for (int j
=0; j
<n
; ++j
){
58 printf("%d %d\n", i
+1, j
+1);